Skip to content

Conversation

@stephdkv
Copy link

@stephdkv stephdkv commented Dec 6, 2022

No description provided.

Copy link

@n05tr0m0 n05tr0m0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Прокомментировал

if is_male[name]:
print(f'{name} мужской род')
else:
print(f'{name} женский род')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно одной строкой в данном случае:

print(name, 'мужской пол') if is_male[name] else print(name, 'женский пол')


students_names = count_name(students)
for name, repeats in students_names.items():
print(f'{name}: {repeats}')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Решение без Counter для ознакомления:

count_students = {}
for student in students:
    if student['first_name'] not in count_students.keys():
        count_students[student['first_name']] = 1
    else:
        count_students[student['first_name']] += 1
print(count_students)
for name, count in count_students.items():
    print(f"{name}: {count}")

names = count_name(students)
most_common_name = name_max_value(names)
print(f'Самое частое имя в классе: {most_common_name}')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Решение без Counter, для ознакомления:

students_list = [student['first_name'] for student in students]
print("Самое частое имя среди учеников:", max(set(students_list), key=students_list.count))

for i, school_class in enumerate(school_students):
names = count_name(school_class)
most_common_name = name_max_value(names)
print(f'Самое частое имя в классе {i+1}: {most_common_name}')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Переиспользование уже написанных функций хороший подход.
Публикую решение без использования Counter для ознакомления:

for num, students in enumerate(school_students, start=1):
    students_list = [student['first_name'] for student in students]
    print(f"Самое частое имя в классе {num}: {max(set(students_list), key=students_list.count)}")

Почитай, попробуй разобраться как это работает, если не получится, напиши мне.

for school_class in school:
gender = students_gender(school_class['students'])
class_name = school_class['class']
print(f"Класс {class_name}: девочки {gender['Female']}, мальчики {gender['Male']}")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ещё два способа решения для этой задачи для ознакомления:

for class_ in school:
    count_boys = 0
    count_girls = 0
    for student in class_['students']:
        if is_male[student['first_name']]:
            count_boys += 1
        else:
            count_girls += 1
    print(f"Класс {class_['class']}: девочки {count_girls}, мальчики {count_boys}")

print("альтернативный способ")  # альтернативный способ
for class_ in school:
    female = [name['first_name'] for name in class_['students'] if not is_male[name['first_name']]]
    male = [name['first_name'] for name in class_['students'] if is_male[name['first_name']]]
    print(f"Класс {class_['class']}: девочки {len(female)}, мальчики {len(male)}")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Когда разберёшь, выполни 5-е задание

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants